package hadoopLearn.Else;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
import scoreAnalyze.CourseMapper;

import java.io.IOException;

public class CourseMax {
    public static void main(String[] args)
        throws IOException, InterruptedException, ClassNotFoundException
    {
        String nameNodeUrl = "hdfs://master:9000";
        String nameNodeName = "fs.defaultFS";
        Configuration conf = new Configuration();
        conf.set(nameNodeName, nameNodeUrl);
        String[] ortherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
        if(ortherArgs.length!=2){
            System.err.println("提示：CourseMax <in> <out>");
            System.exit(2);
        }
        Job job = Job.getInstance(conf, "CourseMax");
        job.setJarByClass(CourseMax.class);
        job.setMapperClass(CourseMapper.class);
        job.setReducerClass(CourseReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        FileInputFormat.addInputPath(job, new Path(ortherArgs[0]));
        FileOutputFormat.setOutputPath(job, new Path(ortherArgs[1]));
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}
